package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.PayParam
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IOdinPayView
import de.baumann.browser.model.OrderModel

open class OdinPayPresenter<V : IOdinPayView> : BasePresenter<V>() {
    fun odinPay(password: String) {
        OrderModel().odinPay(view.getPayId(), password)
                .subscribe(object : OdinObserver<PayParam>(view) {
                    override fun onSuccess(data: PayParam?) {
                        if (view == null) {
                            return
                        }

                        if (password.isEmpty()) {
                            view.wxPay(data)
                            return
                        }

                        view.paySuccess()
                    }
                })
    }
}